package com.olddriver.crm.web.controller;

import com.olddriver.crm.domain.ClientPlan;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.ClientPlanQueryObject;
import com.olddriver.crm.service.IClientPlanService;
import com.olddriver.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("clientPlan")
public class ClientPlanController {
    @Autowired
    private IClientPlanService clientPlanService;

    @RequestMapping("view")
    public String fake_view() {
        return "client/client_plan";
    }

    @ResponseBody
    @RequestMapping("selectAllPlan")
    public PageResult selectAllPlan(ClientPlanQueryObject qo) {
        PageResult result = clientPlanService.query(qo);
        return result;
    }

    @ResponseBody
    @RequestMapping("saveOrUpdate")
    public JsonResult saveOrUpdate(ClientPlan clientPlan) {
        try {
            if (clientPlan.getId() != null) {
                clientPlanService.update(clientPlan);
            } else {
                clientPlanService.save(clientPlan);
            }
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.faliure();
        }
    }

    @ResponseBody
    @RequestMapping("delete")
    public JsonResult delete(Long id) {
        try {
            if(id != null){
               clientPlanService.delete(id);
            }
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.faliure();
        }
    }

    //标记
    @ResponseBody
    @RequestMapping("sign")
    public JsonResult delete(Long id,Integer result_id) {
        try {
            clientPlanService.sign(id,result_id);
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.faliure();
        }
    }



}
